Option Strict Off
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Diagnostics
Imports System.Threading



Public Class FSL_Fast
    Dim ofd1 As New OpenFileDialog
    Dim ex As New ShellClass


    Private Sub AIRbasedRegistration_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ofd1.Filter = "Analyze (*.hdr)|*.hdr"
        ofd1.Title = "Choose the file"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ofd1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = ofd1.FileName
        End If
    End Sub
    Dim tempfilename As String = System.IO.Path.GetTempFileName

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        
        Dim command As String = Chr(34) & My.Application.Info.DirectoryPath & "\FSL\bin\fast_exe.exe" & Chr(34) & " -v5: -e: -or: "

        If CheckedListBox1.CheckedItems.Contains(CheckedListBox1.Items(0)) Then
            If MsgBox("Use Apriori Information for both Initialization & Posteriors? ", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                command += "-Ap " & Chr(24) & System.IO.Path.GetDirectoryName(TextBox1.Text) & System.IO.Path.GetFileNameWithoutExtension(TextBox1.Text) & Chr(34) & " "
            Else
                command += "-ap " & Chr(24) & System.IO.Path.GetDirectoryName(TextBox1.Text) & System.IO.Path.GetFileNameWithoutExtension(TextBox1.Text) & Chr(34) & " "
            End If
        End If
        If CheckedListBox1.CheckedItems.Contains(CheckedListBox1.Items(1)) Then
            command += "-os "
        End If
        If CheckedListBox1.CheckedItems.Contains(CheckedListBox1.Items(2)) Then
            command += "-op "
        End If
        If CheckedListBox1.CheckedItems.Contains(CheckedListBox1.Items(3)) Then
            command += "-ob "
        End If
        If CheckedListBox1.CheckedItems.Contains(CheckedListBox1.Items(4)) Then
            command += "-ov "
        End If
        command += Chr(34) & TextBox1.Text & Chr(34)
            logbox.Text += command & vbNewLine
            logbox.Select(logbox.Text.Length, 0)
        logbox.ScrollToCaret()
        ex.UseNewThread = True
        ex.CaptureOutput = True
        ex.CaptureError = True
        MsgBox("Please manually note the values of means for GM,WM and CSF from Iteration 8 manually")
        Shell(command, AppWinStyle.MaximizedFocus, True)

        logbox.Text += "Done." & vbNewLine & vbNewLine
        logbox.Select(logbox.Text.Length, 0)
        logbox.ScrollToCaret()

    End Sub


End Class
